package org.rc.util;

import cn.hutool.extra.pinyin.PinyinUtil;
import org.apache.commons.lang3.StringUtils;

public class PinyinHelper {

    public static String getPinYin(String worlds){
        worlds = worlds.replaceAll(" ","");
        if(StringUtils.isEmpty(worlds)){
            return "";
        }
        String pinYinStr = PinyinUtil.getPinyin(worlds.trim());
        String result = "";
        if(StringUtils.isNotEmpty(pinYinStr)){
            String[] pinYinArr = pinYinStr.split(" ");
            for(int i=0; i<pinYinArr.length; i++){
                if(StringUtils.isEmpty(pinYinArr[i])){
                    continue;
                }
                result += pinYinArr[i];
            }
        }
        return result;
    }
}
